home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2162 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.tu-chemnitz.de!news
  2. From: hfst@hrz.tu-chemnitz.de (Hans Steffani)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Returning a variable from system() function
  5. Date: 19 Jan 96 15:02:28 GMT
  6. Organization: University of Technology Chemnitz, FRG
  7. Message-ID: <4doc5c$aet@pyrrhus-f.hrz.tu-chemnitz.de>
  8. References: <295336694wnr@iiga.demon.co.uk>
  9. NNTP-Posting-Host: mmu.hrz.tu-chemnitz.de
  10.  
  11. Pete Ryan <pete@iiga.demon.co.uk> writes:
  12.  
  13. >#include <stdio.h>
  14. >#include <stdlib.h>
  15.  
  16. >void main()
  17. >{
  18. >    char    tmp[];
  19. >    
  20. >    chdir("/usr2/willesden");    
  21. >    
  22. >    */ offending code below ;( */
  23. >    tmp = system("find . -name gwire");
  24.  
  25. >    printf("%s",tmp");
  26.  
  27. >}
  28.  
  29. >Therefore if I run `find . -name gwire -print` it returns all the 
  30. >directories containing `gwire`.  However the code above does not 
  31. >work!!. Is it because `= system` returns an integer and not strings???
  32.  
  33. >Any help would be very much appreciated as I have only just started 
  34. >learning c in the last 2 months.  
  35.  
  36. Reading the manual, you find out that system() returns the exit state
  37. of the shell which is hopefully 0.
  38. Perhaps.
  39.  tmp = system("find . -name gwire > tmp_datei.tmp");
  40. and inspecting tmp_datei.tmp afterwards (if tmp==0) can solve your
  41. problem.
  42.  
  43. You also should change the definition of tmp to
  44.  int tmp;
  45.  
  46. You also should change main() to
  47.  int main()
  48.  
  49. h.f.s.
  50. h.f.s.
  51. --
  52. Hans Friedrich Steffani
  53. Institut fuer Elektrische Maschinen und Antriebe
  54. TU Chemnitz-Zwickau
  55. e-mail: hans.steffani@e-technik.tu-chemnitz.de
  56.